

function say() {
    alert("LC:59. 螺旋矩阵 II");
}
say();


/**
 * @param {number} n
 * @return {number[][]}
 */
var generateMatrix = function(n) {
    //7:00-7:15 17-30
    var left = 0; var right = n - 1; var top = 0; var bottom = n - 1
    var res = []
    for(var i = 0; i < n; i++){
        res.push([])
        for(var j = 0; j < n;j++){
            res[i].push(1)
        }
    }

    var num = 1
    while(num <= n * n){
        for(var i = left; i <= right; i++){
            res[top][i] = num
            num++
        }
        top ++
        for(var i = top; i <= bottom; i++){
            res[i][right] = num
            num ++
        }
        right--
        for(var i = right; i >= left; i--){
            res[bottom][i] = num
            num++
        }
        bottom--
        for(var i = bottom; i >= top; i--){
            res[i][left] = num
            num++
        }
        left++
    }
    return res
};


//参考
//https://leetcode-cn.com/problems/spiral-matrix-ii/solution/spiral-matrix-ii-mo-ni-fa-she-ding-bian-jie-qing-x/
